
<template>
    <el-checkbox v-model="currentValue">{{label}}</el-checkbox>
    
</template>
 
<script>
    export default {
        props:['id','label','value','data'],
        name: "input-simple-checkbox",
        data(){
            return {
                currentValue:this.value,
                pId:"",
                cId:"",
                first:'Y',
                currentValueOld:''
            }
        },
        created(){
            let ids=this.id.split(".");
            if(ids.length>1){
                let p=ids[0];
                let id_=ids[1];
                this.pId=p;
                this.cId=id_;
               // this.currentValue=this.data[p][id_]=="Y"||this.data[p][id_]=="是" ? true:false;
                this.currentValue=unescape(this.data[p][id_]);
            }
            
        },
        watch:{
            currentValue: function (val) { //currentValue值变动就向父组件传值
                if(this.first=='Y'){
                    this.currentValueOld=this.currentValue;
                    this.first='N';
                }
                if(this.currentValueOld!=this.currentValue){
                    
                    let data={};
                    data.id=this.id;
                    data.val=val;
                    if(this.pId){
                        this.$set(this.data[this.pId],this.cId,val)
                    }else{
                        this.$set(this.data,this.id,val)
                    }
                     this.GLOBAL.isChange=true;
                     this.currentValueOld=this.currentValue;
                }
                
                //this.$emit('input',JSON.stringify(data));
                //this.$emit('on-change',JSON.stringify(data));
            },
            value:function (val) { //对值进行验证0
                
            }
        }
    }
</script>
<style >
    .el-checkbox{
        margin-top:20px !important;
    }
</style>